home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / 3D & Offscreen for MacApp 3 / 3D & Offscreen Sample.sea / 3D & Offscreen Sample / T3DObjectView.cp < prev    next >
Text File  |  1993-05-21  |  19KB  |  666 lines

  1. /*************************************************************************
  2.  
  3.         File: T3DObjectView.h
  4.  
  5.         C O P Y R I G H T    N O T I C E
  6.  
  7.          Copyright ⌐ 1989, 1990, 1991, 1992 Siemens Gammasonics, Inc.
  8.         All Rights Reserved.
  9.         No portions of this source code or the resulting compiled
  10.         program may be used without express written consent and liscensing
  11.         by Siemens Gammasonics, Inc.
  12.  
  13.  
  14.         D E S C R I P T I O N
  15.  
  16.  
  17.         Classes Defined Here:
  18.  
  19.              Ñ
  20.  
  21.  
  22.      Change History
  23.  
  24.         Rev 1    Wed, Apr 14, 1993 @ 1:17 PM        Hanig
  25.             Creation
  26.  
  27.  *************************************************************************/
  28. /*************************************************************************/
  29. /*                            Include Files                                 */
  30. /*************************************************************************/
  31. #ifndef        __T3DObjectView__
  32. #include    "T3DObjectView.h"
  33. #endif
  34. #ifndef        __TVirtualSphere3DTracker__
  35. #include    "TVirtualSphere3DTracker.h"
  36. #endif
  37. #ifndef        __TOffscreenAdorner__
  38. #include    "TOffscreenAdorner.h"
  39. #endif
  40. #ifndef        __RESOURCES__
  41. #include    <Resources.h>
  42. #endif
  43. #ifndef        __UMACAPPUTILITIES__
  44. #include    <UMacAppUtilities.h>
  45. #endif
  46. #ifndef        __UFAILURE__
  47. #include    <UFailure.h>
  48. #endif
  49. #ifndef        __UDOCUMENT__
  50. #include    <UDocument.h>
  51. #endif
  52. #ifndef        __UDIALOG__
  53. #include    <UDialog.h>
  54. #endif
  55. #ifndef        __UERRORMGR__
  56. #include    <UErrorMgr.h>
  57. #endif
  58. #ifndef        __UMENUMGR__
  59. #include    <UMenuMgr.h>
  60. #endif
  61. #ifndef        __MATH__
  62. #include    <Math.h>
  63. #endif
  64. #ifndef        __FIXMATH__
  65. #include    <FixMath.h>
  66. #endif
  67. #ifndef        _SANE_
  68. #include    <SANE.h>
  69. #endif
  70. #ifndef        __LIMITS__
  71. #include    <Limits.h>
  72. #endif
  73. #include    "Consts.h"
  74.  
  75. /*************************************************************************/
  76. /*                                Constants                                     */
  77. /*************************************************************************/
  78. const short rDitherPatterns = 128;
  79.  
  80. #define    kRWeight        6
  81. #define    kGWeight        4
  82. #define    kBWeight        3
  83. #define    kTotalWeight    (kRWeight + kGWeight + kBWeight)
  84.  
  85. /*************************************************************************/
  86. T3DObjectView::T3DObjectView( void )
  87. {
  88.  
  89. }
  90.  
  91. /*************************************************************************/
  92. #pragma segment MAOpen
  93. pascal void T3DObjectView::Initialize()
  94. {
  95.     inherited::Initialize ();
  96.     
  97.     fPolyNet = NULL;
  98.     fDrawInColor = gConfiguration.hasColorQD;
  99.     fPolyShade = NULL;
  100.     fRemoveBackfacedPolygon = true;
  101.     fRenderingStyle = iFlatShadingWithOutline;    // iLineDrawing, iFlatShading, iFlatShadingWithOutline
  102.     f3DTracker = cRotationTracker;
  103.  
  104.     // preload dither patterns for black & white.
  105.     PatListHandle    theDitherPatterns;
  106.     theDitherPatterns = (PatListHandle) GetResource ('PAT#', rDitherPatterns);
  107.     DetachResource ((Handle) theDitherPatterns);
  108.     FailMemError();
  109.     MoveHHi ((Handle) theDitherPatterns );
  110.     FailMemError();
  111.     HNoPurge ((Handle) theDitherPatterns );
  112.     FailMemError();
  113.     HLock ((Handle) theDitherPatterns);
  114.     FailMemError();
  115.     fDitherPatterns = theDitherPatterns;
  116.     
  117.     // Set matrix to Null
  118.     fObjectMatrix [0][0] = fObjectMatrix [1][1] = fObjectMatrix [2][2] = fObjectMatrix [3][3] = 1;
  119.     fObjectMatrix [0][1] = fObjectMatrix [0][2] = fObjectMatrix [0][3] = 
  120.     fObjectMatrix [1][0] = fObjectMatrix [1][2] = fObjectMatrix [1][3] = 
  121.     fObjectMatrix [2][0] = fObjectMatrix [2][1] = fObjectMatrix [2][3] = 
  122.     fObjectMatrix [3][0] = fObjectMatrix [3][1] = fObjectMatrix [3][2] = 0;
  123. }
  124.  
  125.  
  126. /*************************************************************************/
  127. #pragma segment MAOpen
  128. pascal void T3DObjectView::DoPostCreate(TDocument* itsDocument)
  129. {
  130.     inherited::DoPostCreate (itsDocument);
  131.  
  132.     // This will add transparent offscreen handling.
  133.     // Due to an Error in MacApp, the Adorner must be added manually
  134.     TOffscreenAdorner* aOffscreenAdorner = new TOffscreenAdorner;
  135.     aOffscreenAdorner->IOffscreenAdorner('OffA', true, false );
  136.     this->AddAdorner (aOffscreenAdorner, kAdornFirst, false);
  137.  
  138.     CRect    drawArea;
  139.     Fixed    cubeSize;
  140.     this->GetQDExtent (drawArea);
  141.     long shortestSide = drawArea.right;
  142.     if ( drawArea.bottom < drawArea.right )
  143.         shortestSide = drawArea.bottom;
  144.     cubeSize = MyLong2Fix((long)(shortestSide));
  145.  
  146.     LookAt ( -cubeSize, cubeSize, cubeSize, -cubeSize );
  147.     ViewAngle (MyLong2Fix (25));
  148.     Scale (MyLong2Fix (1), MyLong2Fix (1), MyLong2Fix (1));
  149.     Matrix2XfMatrix (fObjectMatrix, fThe3DPort.xForm);
  150.  
  151.     this->SetObjectType (cIcosahedron);
  152. }
  153.  
  154.  
  155. /*************************************************************************/
  156. #pragma segment MAViewNonRes
  157. pascal void T3DObjectView::SetFrame(const VRect& newFrame, Boolean invalidate)
  158. {
  159.     inherited::SetFrame (newFrame, invalidate);
  160.     
  161.     // maybe we should scale here.
  162.     
  163.     this->ForceRedraw();
  164. }
  165.  
  166.  
  167. /*************************************************************************/
  168. #pragma segment ThreeDSeg
  169. pascal void T3DObjectView::Matrix2XfMatrix (Matrix4D fromMatrix, XfMatrix toMatrix)
  170. {
  171.     long i, j;
  172.     
  173.     for (i=3; i>=0; i--)
  174.         for (j=3; j>=0; j--)
  175.             toMatrix[i][j]= X2Fix (fromMatrix[i][j]);
  176.  
  177.  
  178. #ifdef xxxxxxxxxxxxxxxxxxxxxxxxxNOT_USEDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  179.     /* Faster but kludgy version of the same thing */
  180.     
  181.     double    *fromPtr = (double  *) fromMatrix;
  182.     Fixed    *toPtr   = (Fixed *) toMatrix;
  183.     long i;
  184.     for (i=15; i>=0; i--) {
  185.         *toPtr++ = X2Fix (*fromPtr++);
  186.     }
  187. #endif xxxxxxxxxxxxxxxxxxxxxxxxxNOT_USEDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  188. }
  189.  
  190.  
  191. /*************************************************************************/
  192. #pragma segment ThreeDSeg
  193. pascal void T3DObjectView::MultiplyMatrix (Matrix4D a, Matrix4D b, Matrix4D aTimesB)
  194. {
  195.     long i, j, k;
  196.  
  197.     for (i=3; i>=0; i--) 
  198.     {
  199.         for (j=3; j>=0; j--) 
  200.         {
  201.             double sum = 0.0;
  202.             for (k=3; k>=0; k--)
  203.                 sum += a[i][k] * b[k][j];
  204.             aTimesB[i][j]= sum;
  205.         }
  206.     }
  207. }
  208.  
  209. /*************************************************************************/
  210. #pragma segment MAViewRes
  211. pascal void T3DObjectView::Draw(const VRect& /*area*/)
  212. {
  213.     CRect    drawArea;
  214.     short    shortestSide;
  215.     short    sphereRadius;
  216.  
  217.     DrawPolyNet ();        // draw polygon
  218.     
  219.     PenNormal();        // with only line drawing on, the pen gets set
  220.     
  221.     // dont draw oval at edges of frame
  222.     this->GetQDExtent (drawArea);
  223.     shortestSide = drawArea.right;
  224.     if ( drawArea.right > drawArea.bottom )
  225.         shortestSide = drawArea.bottom;
  226.     shortestSide = shortestSide/2;
  227.     sphereRadius   = (short)(shortestSide * kSphereRadius);
  228.     SetRect(drawArea, shortestSide - sphereRadius, shortestSide - sphereRadius,
  229.                       shortestSide + sphereRadius, shortestSide + sphereRadius );
  230.     FrameOval (drawArea);
  231. }
  232.  
  233.  
  234. /*************************************************************************/
  235. #pragma segment ThreeDSeg
  236. pascal void T3DObjectView::DrawPolyNet ( )
  237. {
  238.     if ( fPolyNet )
  239.     {
  240.         Point3D*    vertices;            // local index into the vertex array
  241.         long*        vertexIndices;
  242.         long        count;
  243.         
  244.         if (fPolyNet->fVertexCount < 0)
  245.             return;//DebugMessage ("\pfVertexCount < 0");
  246.     
  247.         vertices = fPolyNet->fVertices;
  248.         vertexIndices = fPolyNet->fVertexIndices;
  249.         
  250.         // For each polygon...
  251.         for (count = 0; count < fPolyNet->fPolygonCount; count++) 
  252.         {
  253.             long firstVertexIndex;
  254.             NetPolygon* thisPoly = &fPolyNet->fPolys[count];
  255.             if (thisPoly->fVertexCount < 3) 
  256.                 continue;    // This is not a polygon.  Skip to next one.
  257.             firstVertexIndex = thisPoly->fFirstVertexIndex;
  258.             
  259.             if ( fRemoveBackfacedPolygon ) 
  260.             {
  261.                 // Transform first 3 points to screen coordinate to do backface polygon test.
  262.                 // Code will not work if any vertex is offscreen!
  263.                 CPoint p0, p1, p2;
  264.                 long v1h, v1v, v2h, v2v;
  265.                 
  266.                 MoveTo3D (vertices [vertexIndices [firstVertexIndex  ]].x,
  267.                           vertices [vertexIndices [firstVertexIndex  ]].y,
  268.                           vertices [vertexIndices [firstVertexIndex  ]].z);
  269.                 GetPen (p0);
  270.                 MoveTo3D (vertices [vertexIndices [firstVertexIndex+1]].x,
  271.                           vertices [vertexIndices [firstVertexIndex+1]].y,
  272.                           vertices [vertexIndices [firstVertexIndex+1]].z);
  273.                 GetPen (p1);
  274.                 MoveTo3D (vertices [vertexIndices [firstVertexIndex+2]].x,
  275.                           vertices [vertexIndices [firstVertexIndex+2]].y,
  276.                           vertices [vertexIndices [firstVertexIndex+2]].z);
  277.                 GetPen (p2);
  278.     
  279.                 v1h = p1.h - p0.h;
  280.                 v1v = p1.v - p0.v;
  281.                 v2h = p2.h - p1.h;
  282.                 v2v = p2.v - p1.v;
  283.     
  284.                 // Check for backfaced polygon by doing cross-product.  Skip if backfaced.
  285.                 // Try using '<=' test instead to get the inside-out effect 
  286.                 if ((v1h * v2v - v1v * v2h) >= 0) 
  287.                     continue;
  288.             }
  289.     
  290.             {
  291.                 // Draw the polygon
  292.                 
  293.                 PolyHandle    polyHdl = nil;
  294.                 long j;
  295.                 long vertexIndex;
  296.     
  297.                 if (fRenderingStyle != iLineDrawing) 
  298.                 {
  299.                     // fRenderingStyle is iFlatShading or iFlatShadingWithOutline.
  300.                     // Begin collecting QD polygon
  301.                     polyHdl = OpenPoly ();
  302.                 }
  303.                 PolyColor (fPolyNet->fColor[thisPoly->fColorIndex]);
  304.                 
  305.                 // Initial move
  306.                 vertexIndex = vertexIndices [firstVertexIndex];
  307.                 MoveTo3D    (    vertices [vertexIndex].x,
  308.                                 vertices [vertexIndex].y,
  309.                                 vertices [vertexIndex].z);
  310.                 // Hit the vertices            
  311.                 for (j = firstVertexIndex+1; j < firstVertexIndex+thisPoly->fVertexCount; j++)
  312.                 {
  313.                     vertexIndex = vertexIndices [j];
  314.                     LineTo3D(    vertices [vertexIndex].x,
  315.                                 vertices [vertexIndex].y,
  316.                                 vertices [vertexIndex].z);
  317.                 }
  318.                 // Close the polygon
  319.                 vertexIndex = vertexIndices [firstVertexIndex];
  320.                 LineTo3D    (    vertices [vertexIndex].x,
  321.                                 vertices [vertexIndex].y,
  322.                                 vertices [vertexIndex].z);
  323.                 
  324.                 if (fRenderingStyle != iLineDrawing) 
  325.                 {
  326.                     ClosePoly ();                      // Stop collecting QD polygon
  327.                     FillPoly (polyHdl, fPolyShade);
  328.                     if (fRenderingStyle == iFlatShadingWithOutline) 
  329.                     {
  330.                         ForeColor (blackColor);
  331.                         FramePoly (polyHdl);
  332.                     }
  333.                     KillPoly (polyHdl);
  334.                 }
  335.             }
  336.         }
  337.     }
  338. }
  339.  
  340.  
  341. /*************************************************************************/
  342. #pragma segment ThreeDSeg
  343. pascal void T3DObjectView::SetPolyNet( PolygonNetData* thePolyNet )
  344. {
  345.     fPolyNet = thePolyNet;
  346.     this->ForceRedraw();
  347. }
  348.  
  349. /*************************************************************************/
  350. #pragma segment MASelCommand
  351. pascal void T3DObjectView::DoMouseCommand(VPoint& theMouse,  TToolboxEvent* event,  CPoint hysteresis)
  352. {    
  353.     switch ( f3DTracker )
  354.     {
  355.         case cRotationTracker:
  356.             TVirtualSphere3DTracker * a3DVirtualTracker = new TVirtualSphere3DTracker;
  357.             a3DVirtualTracker->I3DTracker(this, theMouse);
  358.             this->PostCommand(a3DVirtualTracker);
  359.         case cScaleTracker:    // future trackers
  360.         //    TScale3DTracker * a3DScaleTracker = new TScale3DTracker;
  361.         //    a3DScaleTracker->I3DTracker(this, theMouse);
  362.         //    this->PostCommand(a3DScaleTracker);
  363.         //    break;
  364.         default:
  365.             inherited::DoMouseCommand (theMouse, event, hysteresis);
  366.             break;
  367.     }
  368. }
  369.  
  370.  
  371. /*************************************************************************/
  372. #pragma segment ThreeDSeg
  373. pascal void T3DObjectView::PolyColor (const CRGBColor& rGBColor)
  374. {
  375.     if (fDrawInColor) 
  376.     {
  377.         fPolyShade = (ConstPatternParam)(&qd.black);
  378.         RGBForeColor (rGBColor);
  379.     } 
  380.     else 
  381.     {
  382.         // Convert RGB to dither pattern.  Note we use different weighting factors
  383.         // for the RGB components  to come up with a grey value.  This is just 
  384.         // so that more different patterns are shown on the objects.  Note RGB components are shorts.
  385.         unsigned long index;
  386.         unsigned long intensity;
  387.         
  388.         long kMaxPatternIndex = (**fDitherPatterns).patListSize;
  389.         intensity = kRWeight*rGBColor.red + kGWeight*rGBColor.green + kBWeight*rGBColor.blue;
  390.         index = intensity * kMaxPatternIndex / kTotalWeight / USHRT_MAX;    // Note long math.  Order matters 
  391.         if (index >= kMaxPatternIndex) 
  392.             index = kMaxPatternIndex -1;            // Needed?
  393.         fPolyShade = (ConstPatternParam) (&((**fDitherPatterns).patList[index]));
  394.         ForeColor (blackColor);
  395.     }
  396. }
  397.  
  398. /*************************************************************************/
  399. #pragma segment MAClose
  400. pascal void T3DObjectView::Free()
  401. {
  402.     if ( fDitherPatterns == NULL )
  403.         DisposeHandle ((Handle) fDitherPatterns);
  404.     
  405.     inherited::Free();
  406. }
  407.  
  408.  
  409. /*************************************************************************/
  410. #pragma segment ThreeDSeg
  411. pascal void T3DObjectView::CopyMatrix (Matrix4D fromMatrix, Matrix4D toMatrix)
  412. {
  413.     * (MatrixAsStruct *) toMatrix = * (MatrixAsStruct *) fromMatrix;
  414. }
  415.  
  416.  
  417. /*************************************************************************/
  418. #pragma segment ThreeDSeg
  419. pascal void T3DObjectView::SetRotationMatrix (Matrix4D rotationMatrix, const CPoint3D *axis, double radians)
  420. {
  421.     double s, c, t;
  422.     
  423.     #define ax    (axis->x)
  424.     #define ay    (axis->y)
  425.     #define az    (axis->z)
  426.     #define ax2    (ax * ax)
  427.     #define ay2    (ay * ay)
  428.     #define az2    (az * az)
  429.  
  430.     s = sin (radians);
  431.     c = cos (radians);
  432.     t = 1 - c;
  433.  
  434.     rotationMatrix[0][0] = t*ax2+c;
  435.     rotationMatrix[0][1] = t*ax*ay+s*az;
  436.     rotationMatrix[0][2] = t*ax*az-s*ay;
  437.  
  438.     rotationMatrix[1][0] = t*ax*ay-s*az;
  439.     rotationMatrix[1][1] = t*ay2+c;
  440.     rotationMatrix[1][2] = t*ay*az+s*ax;
  441.  
  442.     rotationMatrix[2][0] = t*ax*az+s*ay;
  443.     rotationMatrix[2][1] = t*ay*az-s*ax;
  444.     rotationMatrix[2][2] = t*az2+c;
  445.  
  446.     rotationMatrix[0][3] = rotationMatrix[1][3] = rotationMatrix[2][3] = 
  447.     rotationMatrix[3][0] = rotationMatrix[3][1] = rotationMatrix[3][2] = 0.0;
  448.     rotationMatrix[3][3] = 1.0;
  449.  
  450.     #undef ax
  451.     #undef ay
  452.     #undef az
  453.     #undef ax2
  454.     #undef ay2
  455.     #undef az2
  456. }
  457.  
  458.  
  459. /*************************************************************************/
  460. #pragma segment ThreeDSeg
  461. pascal void T3DObjectView::AdjustforRotation(const CPoint3D* axis, double radians)
  462. {
  463.     Matrix4D    tempMatrix;
  464.     Matrix4D    rotationMatrix;
  465.     
  466.     this->SetRotationMatrix (rotationMatrix, axis, radians);
  467.     
  468.     Boolean wasLocked = this->Lock(true);    // using class variable, don't let float
  469.     this->MultiplyMatrix( fObjectMatrix, rotationMatrix, tempMatrix );
  470.     this->CopyMatrix (tempMatrix, fObjectMatrix);
  471.     this->OrthogonalizeRotationMatrix (fObjectMatrix);
  472.     this->Lock(wasLocked);
  473. }
  474.  
  475. /*************************************************************************/
  476. #pragma segment MAViewRes
  477. pascal Boolean T3DObjectView::Focus()
  478. {
  479.     Boolean result = inherited::Focus ();
  480.     
  481.     Matrix2XfMatrix (fObjectMatrix, fThe3DPort.xForm);
  482.     
  483.     return (result);
  484. }
  485.  
  486. /*************************************************************************/
  487. #pragma segment ThreeDSeg
  488. pascal void T3DObjectView::OrthogonalizeRotationMatrix (Matrix4D matrix)
  489. {
  490.     CPoint3D xAxis, yAxis, zAxis;
  491.  
  492.     yAxis.x = matrix[1][0];
  493.     yAxis.y = matrix[1][1];
  494.     yAxis.z = matrix[1][2];
  495.     zAxis.x = matrix[2][0];
  496.     zAxis.y = matrix[2][1];
  497.     zAxis.z = matrix[2][2];
  498.  
  499.     Normalize3D (&yAxis);
  500.     UnitCrossProduct3D  (&yAxis, &zAxis, &xAxis);
  501.     UnitCrossProduct3D  (&xAxis, &yAxis, &zAxis);
  502.  
  503.     matrix[0][0] = xAxis.x;
  504.     matrix[0][1] = xAxis.y;
  505.     matrix[0][2] = xAxis.z;
  506.  
  507.     matrix[1][0] = yAxis.x;
  508.     matrix[1][1] = yAxis.y;
  509.     matrix[1][2] = yAxis.z;
  510.  
  511.     matrix[2][0] = zAxis.x;
  512.     matrix[2][1] = zAxis.y;
  513.     matrix[2][2] = zAxis.z;
  514. }
  515.  
  516.  
  517. /*************************************************************************/
  518. #pragma segment ThreeDSeg
  519. pascal void T3DObjectView::Normalize3D (CPoint3D* v)
  520. {
  521.     double length;
  522.  
  523.     length = sqrt (v->x * v->x + v->y * v->y + v->z * v->z);
  524.     if (length > 0) 
  525.     {
  526.         v->x /= length;
  527.         v->y /= length;
  528.         v->z /= length;
  529.     }
  530.     else 
  531.     {
  532.         // Vector is zero. This will cause the program to crash. So we
  533.         // get rid of the offending data, and start a new window.
  534.         v->x = v->y = v->z = 0;
  535.         ParamText("the vector was 0", "This error causes loss of matrix normalization.", "rotate the object", gEmptyString);
  536.         MacAppAlert(phGenError, NULL);
  537.         if ( fDocument )
  538.             this->fDocument->CloseAndFree ();
  539.         gApplication->DoMenuCommand (cNew);
  540.         Failure(0,0);
  541.     }
  542. }
  543.  
  544.  
  545. /*************************************************************************/
  546. #pragma segment ThreeDSeg
  547. pascal void T3DObjectView::UnitCrossProduct3D (const CPoint3D *a, const CPoint3D *b, CPoint3D *aCrossB)
  548. {
  549.     CrossProduct3D (a, b, aCrossB);
  550.     Normalize3D (aCrossB);
  551. }
  552.  
  553.  
  554. /*************************************************************************/
  555. #pragma segment ThreeDSeg
  556. pascal void T3DObjectView::CrossProduct3D (const CPoint3D *a,  const CPoint3D *b, CPoint3D *aCrossB)
  557. {
  558.     aCrossB->x = a->y * b->z - a->z * b->y;
  559.     aCrossB->y = a->z * b->x - a->x * b->z;
  560.     aCrossB->z = a->x * b->y - a->y * b->x;
  561. }
  562.  
  563. /*************************************************************************/
  564. #pragma segment MASelCommand
  565. pascal void T3DObjectView::DoMenuCommand(CommandNumber aCommandNumber)
  566. {
  567.     switch (aCommandNumber)
  568.     {
  569.         case cLineDraw:
  570.             fRenderingStyle = iLineDrawing;
  571.             this->ForceRedraw();
  572.             break;
  573.         case cFlatShading:
  574.             fRenderingStyle = iFlatShading;
  575.             this->ForceRedraw();
  576.             break;
  577.         case cFlatwithOutline:
  578.             fRenderingStyle = iFlatShadingWithOutline;
  579.             this->ForceRedraw();
  580.             break;
  581.         
  582.         case cBackFacePolyremove:
  583.             fRemoveBackfacedPolygon = !fRemoveBackfacedPolygon;
  584.             this->ForceRedraw();
  585.             break;
  586.         case cRemoveOffscreen:
  587.             
  588.             break;
  589.         case cCube:
  590.         case cHouse:
  591.         case cIcosahedron:
  592.             SetObjectType (aCommandNumber);
  593.             break;
  594.         
  595.         case cRotationTracker:
  596.         case cScaleTracker:
  597.         case cViewTracker:
  598.             f3DTracker = aCommandNumber;
  599.             break;
  600.  
  601.         default:
  602.             inherited::DoMenuCommand(aCommandNumber);
  603.             break;
  604.     }
  605. }
  606.  
  607.  
  608. /*************************************************************************/
  609. #pragma segment ThreeDSeg
  610. pascal void T3DObjectView::DoSetupMenus()
  611. {
  612.     inherited::DoSetupMenus();
  613.     
  614.     EnableCheck(cLineDraw,            true, fRenderingStyle == iLineDrawing);
  615.     EnableCheck(cFlatShading,        true, fRenderingStyle == iFlatShading);
  616.     EnableCheck(cFlatwithOutline,    true, fRenderingStyle == iFlatShadingWithOutline);
  617.     EnableCheck(cBackFacePolyremove,true, fRemoveBackfacedPolygon);
  618.     
  619.     EnableCheck(cCube,                true, f3DObject == cCube );
  620.     EnableCheck(cHouse,                true, f3DObject == cHouse );
  621.     EnableCheck(cIcosahedron,        true, f3DObject == cIcosahedron );
  622.     
  623.     EnableCheck(cRotationTracker,    true, f3DTracker == cRotationTracker );
  624.     EnableCheck(cScaleTracker,        false, f3DTracker == cScaleTracker );
  625.     EnableCheck(cViewTracker,        false, f3DTracker == cViewTracker );    
  626. }
  627.  
  628. /*************************************************************************/
  629. #pragma segment ThreeDSeg
  630. pascal void T3DObjectView::SetObjectType(CommandNumber newObject)
  631. {
  632.     f3DObject = newObject;
  633.     
  634.     // Set matrix to Null
  635.     //fObjectMatrix [0][0] = fObjectMatrix [1][1] = fObjectMatrix [2][2] = fObjectMatrix [3][3] = 1;
  636.     //fObjectMatrix [0][1] = fObjectMatrix [0][2] = fObjectMatrix [0][3] = 
  637.     //fObjectMatrix [1][0] = fObjectMatrix [1][2] = fObjectMatrix [1][3] = 
  638.     //fObjectMatrix [2][0] = fObjectMatrix [2][1] = fObjectMatrix [2][3] = 
  639.     //fObjectMatrix [3][0] = fObjectMatrix [3][1] = fObjectMatrix [3][2] = 0;
  640.     //Matrix2XfMatrix (fObjectMatrix, fThe3DPort.xForm);
  641.     
  642.     switch (newObject)
  643.     {
  644.         case cCube:
  645.             this->SetPolyNet (&gCubeData);
  646.             break;
  647.         case cHouse:
  648.             this->SetPolyNet (&gHouseData);
  649.             break;
  650.         case cIcosahedron:
  651.             this->SetPolyNet (&gIcosahedronData);
  652.             break;
  653.         default:
  654.             this->SetPolyNet (&gIcosahedronData);
  655.             f3DObject = cIcosahedron;
  656.             break;
  657.     }
  658. }
  659.  
  660.  
  661.  
  662.  
  663.  
  664. /*************************************************************************/
  665. /*************************************************************************/
  666.